/*
 * StripeDetector.cpp
 *
 *  Created on: Apr 30, 2010
 *      Author: Soheil Damangir
 */

#include <iostream>
#include <bitset>

#include "../Util/Constants.h"
#include "Detector.h"
#include "StripeDetector.h"

namespace Group5 {

StripeDetector::StripeDetector(std::istream&is): Detector(is) {}

void StripeDetector::detect(kthrobot::Image&image, DetectionResults&results, const char*what = "Stripe_detector")
{
  Detector::detect(image, results, what);
  if (results.size < Constants::get().MIN_STRIPE_SIZE)
  {
    results.size = 0;
    return;
  }
  results.size = 0;

  std::bitset<STRIPE_HIST> prev;
  bool last_status = false;
  for (int y = _min_y + results.h / 3;y <= _max_y - results.h / 3; y++)
  {
    prev = 0;
    for (int x = _min_x;x <= _max_x; x++)
    {
      prev = prev << 1;
      prev[0] = clr[y][x];
      if (prev.count()==prev.size())
      {
        if (!last_status)
          results.size++;

        last_status = true;

      }else if (!prev.any())
      {
        last_status = false;
      }
    }
  }

}
StripeDetector::~StripeDetector(){}
}

